#!/usr/bin/python
# -*- coding: UTF-8 -*-

import multiprocessing,os,time
from Tools.HDFS import HDFS
from Tools.Logs import Logs
class MuProcess :
    def __init__(self,process_number,cluster1,cluster2,filename):
        self.process_number= process_number
        self.pool =  multiprocessing.Pool(processes=self.process_number)
        self.cluster1 = cluster1
        self.cluster2 = cluster2
        self.filename = filename


    def rundistcp(self):
        for filename  in Logs(self.filename).read():
            for i in range(self.process_number):
                hdfsdir =  filename.split("\n")[0]
                print multiprocessing.current_process().name +"-"+ str(i) +"-"+hdfsdir 
                self.pool.apply_async(HDFS().redistcp(self.cluster1,self.cluster2,hdfsdir))
                #print "filename : %s \n" % filename 
        self.pool.close()  # 关闭进程池，表示不能在往进程池中添加进程
        self.pool.join()  # 等待进程池中的所有进程执行完毕，必须在close()之后调用
        print "Sub-process(es) done."

